package com.ambulance.project.biz.controller.manager;

import com.ambulance.common.utils.poi.ExcelUtil;
import com.ambulance.framework.aspectj.lang.annotation.Log;
import com.ambulance.framework.aspectj.lang.enums.BusinessType;
import com.ambulance.framework.web.controller.BaseController;
import com.ambulance.framework.web.domain.AjaxResult;
import com.ambulance.framework.web.page.TableDataInfo;
import com.ambulance.project.manager.domain.BizDepart;
import com.ambulance.project.manager.service.IBizDepartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 科室Controller
 *
 * @author zr
 * @date 2020-05-11
 */
@RestController
@RequestMapping("/manager/depart")
public class BizDepartController extends BaseController {
    @Autowired
    private IBizDepartService bizDepartService;

    /**
     * 查询科室列表
     */
    //@PreAuthorize("@ss.hasPermi('manager:depart:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizDepart bizDepart) {
        startPage();
        List<BizDepart> list = bizDepartService.selectBizDepartList(bizDepart);
        return getDataTable(list);
    }

    /**
     * 导出科室列表
     */
    //@PreAuthorize("@ss.hasPermi('manager:depart:export')")
    @Log(title = "科室", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BizDepart bizDepart) {
        List<BizDepart> list = bizDepartService.selectBizDepartList(bizDepart);
        ExcelUtil<BizDepart> util = new ExcelUtil<BizDepart>(BizDepart.class);
        return util.exportExcel(list, "depart");
    }

    /**
     * 获取科室详细信息
     */
    //@PreAuthorize("@ss.hasPermi('manager:depart:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(bizDepartService.selectBizDepartById(id));
    }

    /**
     * 新增科室
     */
    //@PreAuthorize("@ss.hasPermi('manager:depart:add')")
    @Log(title = "科室", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizDepart bizDepart) {
        return toAjax(bizDepartService.insertBizDepart(bizDepart));
    }

    /**
     * 修改科室
     */
    //@PreAuthorize("@ss.hasPermi('manager:depart:edit')")
    @Log(title = "科室", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizDepart bizDepart) {
        return toAjax(bizDepartService.updateBizDepart(bizDepart));
    }

    /**
     * 删除科室
     */
    //@PreAuthorize("@ss.hasPermi('manager:depart:remove')")
    @Log(title = "科室", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bizDepartService.deleteBizDepartByIds(ids));
    }
}
